/**
 *=============================================================================
 *  @copyright (C)      2025CCUT_1024lab_Damocles
 *
 *  @file    template.c
 *  @brief   封装模块代码规范
 *
 *  @note    使用方法
 *
 *  @attention 注意事项
 *-----------------------------------------------------------------------------
 *  @version    @author    @date    @note
 *  V1.0.0      Cherno    250808    done
 *
 *==============================================================================
 */

/*==============================Includes======================================*/
#include "UART_receive.h"
#include "cmsis_os2.h"
#include "drv_uart.h"
#include "dvc_DR16.h"
#include "dvc_djimotor.h"
#include "dvc_miniPC.h"
#include "dvc_serialplot.h"
/*==============================PrivateMacros=================================*/

/*==============================PrivateTypes==================================*/

/*==============================PrivateVariables==============================*/
DR16 dr16;
SerialPlot plot;
miniPC PC;
extern GM6020 GM6020_1;

/*==============================PrivateFunctionDeclarations===================*/
void DR16_UART3_Callback(uint8_t *buffer, uint16_t length);
void miniPC_UART1_Callback(uint8_t *buffer, uint16_t length);
void Serialplot_UART1_Callback(uint8_t *buffer, uint16_t length);
/*==============================FunctionPrototypes============================*/

/**
 * @brief : 描述该函数主要功能
 * @note : 注意事项
 *
 * @param : 参数名（与函数里的参数一致）  参数的描述
 * @return : 返回值的说明
 */
void uart_receive_task(void *argument)
{
#if USE_DR16 == 1
	uart_init(&huart3, DR16_UART3_Callback, 18);
	dr16.init(&huart3);
#endif

#if USE_PLOT == 1
	uart_init(&huart1, Serialplot_UART1_Callback, 10);
	// plot.init(&huart1, &GM6020_1.pid_omega);
	plot.init(&huart1, &GM6020_1.pid_omega);

#endif

#if USE_MINIPC == 1
	uart_init(&huart1, miniPC_UART1_Callback, 256);
	PC.init(&huart1);
#endif

	while (1) {
#if USE_DR16 == 1
		plot.vofa_just_float_dma(
		    "%f%f%f%f%f%f%f", dr16.get_left_X(), dr16.get_left_Y(),
		    dr16.get_right_X(), dr16.get_right_Y(),
		    (float)dr16.get_left_switch(), (float)dr16.get_right_switch(),
		    dr16.get_yaw());
#endif
#if USE_PLOT == 1
		plot.vofa_show_pid_loop();
		GM6020_1.set_target_omega(plot.single_loop->get_target());
		// GM6020_1.set_target_angle(plot.single_loop->get_target());

#endif

#if USE_MINIPC == 1
		PC.vs_tx_data = {
		    .detect_color = 0,
		    .reset_tracker = 1,
		    .reserved = 0,
		    .roll = 1.1,
		    .pitch = 4.5,
		    .yaw = 1.4,
		};
		PC.send_packet_data(VERSION_LABLE, &PC.vs_tx_data,
		                    sizeof(PC.vs_tx_data));

		plot.vofa_just_float_dma(
		    "%f%f%f%f%f%f%f%f%f", (float)PC.vs_rx_data.tracking,
		    (float)PC.vs_rx_data.id, (float)PC.vs_rx_data.armors_num,
		    PC.vs_rx_data.yaw, PC.vs_rx_data.pitch, PC.vs_rx_data.fire,
		    PC.vs_rx_data.v_yaw, PC.vs_rx_data.distance, PC.vs_rx_data.is_fire);
#endif

		osDelay(3);
	}
}

void DR16_UART3_Callback(uint8_t *buffer, uint16_t length)
{
	dr16.UART_RxCallback(buffer);
}

void miniPC_UART1_Callback(uint8_t *buffer, uint16_t length)
{
	PC.UART_RxCallback(buffer);
}

void Serialplot_UART1_Callback(uint8_t *buffer, uint16_t length)
{
	plot.UART_RxCallback(buffer);
}
/*========================COPYRIGHT(C) CCUT-DAMOCLES==========================*/